package ics414scuba;

/*DISCLAIMER: This is a PROTOTYPE and must NOT be used to plan real dives.
 * 
 */

public class DiveTable{
	
	/*DISCLAIMER: This is a PROTOTYPE and must NOT be used to plan real dives.
	 *
	 */
	public DiveTable(){}
	
	/*DISCLAIMER: This is a PROTOTYPE and must NOT be used to plan real dives.
	 * 
	 * @return char that contains the group letter for the repetive dive table that is capatalized. If 0, then the break time is invalid 
	 */
	public char breakGroupCalculator(char group, int time){
		char returnGroup = 0;
		if(time < 10){
		}
		else if(time > 553 || group == 'A'){
			returnGroup = 'A';
		}
		else{
			 returnGroup = breakGroupCalculate(group, time);
		}
		return returnGroup;
	}
	
	/* DISCLAIMER: This is a PROTOTYPE and must NOT be used to plan real dives.
	 * 
	 * Private method for caculating the 
	 * @return char that contains the group letter for the repetive dive table that is capatalized.  
	 */
	private char breakGroupCalculate(char group, int time){
		char returnGroup = 0;
		
		if(group == 'B'){
			if(time >= 201){
				returnGroup = 'A';
			}
			else if(time <= 200){
				returnGroup = 'B';
			}
			
		}
		else if(group == 'C'){
			if(time >= 290){
				returnGroup = 'A';
			}
			else if(time <= 289 && time >= 120){
				returnGroup = 'B';
			}
			else{
				returnGroup = 'C';
			}
		}
		else if(group == 'D'){
			if(time >= 349){
				returnGroup = 'A';
			}
			else if(time <= 348 && time >= 159){
				returnGroup = 'B';
			}
			else if(time <= 158 && time >= 70){
				returnGroup = 'C';
			}
			else{
				returnGroup = 'D';
			}
		}
		else if(group == 'E'){
			if(time >= 395){
				returnGroup = 'A';
			}
			else if(time <= 394 && time >= 204){
				returnGroup = 'B';
			}
			else if(time <= 204 && time >= 118){
				returnGroup = 'C';
			}
			else if(time <= 117 && time >= 55){
				returnGroup = 'D';
			}
			else{
				returnGroup = 'E';
			}
		}
		else if(group == 'F'){
			if(time >= 426){
				returnGroup = 'A';
			}
			else if(time <= 425 && time >= 238){
				returnGroup = 'B';
			}
			else if(time <= 237 && time >= 149){
				returnGroup = 'C';
			}
			else if(time <= 148 && time >= 90){
				returnGroup = 'D';
			}
			else if(time <= 89 && time >= 46){
				returnGroup = 'E';
			}
			else{
				returnGroup = 'F';
			}
		}
		else if(group == 'G'){
			if(time >= 456){
				returnGroup = 'A';
			}
			else if(time <= 455 && time >= 266){
				returnGroup = 'B';
			}
			else if(time <= 265 && time >= 179){
				returnGroup = 'C';
			}
			else if(time <= 178 && time >= 120){
				returnGroup = 'D';
			}
			else if(time <= 119 && time >= 76){
				returnGroup = 'E';
			}
			else if(time <= 75 && time >= 41){
				returnGroup = 'F';
			}
			else{
				returnGroup = 'G';
			}
		}
		else if(group == 'H'){
			if(time >= 480){
				returnGroup = 'A';
			}
			else if(time <= 479 && time >= 290){
				returnGroup = 'B';
			}
			else if(time <= 289 && time >= 201){
				returnGroup = 'C';
			}
			else if(time <= 200 && time >= 144){
				returnGroup = 'D';
			}
			else if(time <= 143 && time >= 102){
				returnGroup = 'E';
			}
			else if(time <= 101 && time >= 67){
				returnGroup = 'F';
			}
			else if(time <= 66 && time >= 37){
				returnGroup = 'G';
			}
			else{
				returnGroup = 'H';
			}
		}
		else if(group == 'I'){
			if(time >= 502){
				returnGroup = 'A';
			}
			else if(time <= 501 && time >= 313){
				returnGroup = 'B';
			}
			else if(time <= 312 && time >= 224){
				returnGroup = 'C';
			}
			else if(time <= 223 && time >= 165){
				returnGroup = 'D';
			}
			else if(time <= 164 && time >= 123){
				returnGroup = 'E';
			}
			else if(time <= 122 && time >= 90){
				returnGroup = 'F';
			}
			else if(time <= 89 && time >= 60){
				returnGroup = 'G';
			}
			else if(time <= 59 && time >= 34){
				returnGroup = 'H';
			}
			else{
				returnGroup = 'I';
			}
		}
		else if(group == 'J'){
			if(time >= 531){
				returnGroup = 'A';
			}
			else if(time <= 530 && time >= 341){
				returnGroup = 'B';
			}
			else if(time <= 340 && time >= 243){
				returnGroup = 'C';
			}
			else if(time <= 242 && time >= 185){
				returnGroup = 'D';
			}
			else if(time <= 184 && time >= 141){
				returnGroup = 'E';
			}
			else if(time <= 140 && time >= 108){
				returnGroup = 'F';
			}
			else if(time <= 107 && time >= 80){
				returnGroup = 'G';
			}
			else if(time <= 79 && time >= 55){
				returnGroup = 'H';
			}
			else if(time <= 54 && time >= 32){
				returnGroup = 'I';
			}
			else{
				returnGroup = 'J';
			}
		}
		else if(group == 'K'){
			if(time >= 539){
				returnGroup = 'A';
			}
			else if(time <= 538 && time >= 349){
				returnGroup = 'B';
			}
			else if(time <= 348 && time >= 260){
				returnGroup = 'C';
			}
			else if(time <= 259 && time >= 202){
				returnGroup = 'D';
			}
			else if(time <= 201 && time >= 159){
				returnGroup = 'E';
			}
			else if(time <= 158 && time >= 124){
				returnGroup = 'F';
			}
			else if(time <= 123 && time >= 96){
				returnGroup = 'G';
			}
			else if(time <= 95 && time >= 72){
				returnGroup = 'H';
			}
			else if(time <= 71 && time >= 50){
				returnGroup = 'I';
			}
			else if(time <= 49 && time >= 29){
				returnGroup = 'J';
			}
			else{
				returnGroup = 'K';
			}
		}
		else {
			if(time >= 553){
				returnGroup = 'A';
			}
			else if(time <= 552 && time >= 363){
				returnGroup = 'B';
			}
			else if(time <= 362 && time >= 276){
				returnGroup = 'C';
			}
			else if(time <= 275 && time >= 217){
				returnGroup = 'D';
			}
			else if(time <= 216 && time >= 174){
				returnGroup = 'E';
			}
			else if(time <= 173 && time >= 140){
				returnGroup = 'F';
			}
			else if(time <= 139 && time >= 110){
				returnGroup = 'G';
			}
			else if(time <= 109 && time >= 86){
				returnGroup = 'H';
			}
			else if(time <= 85 && time >= 65){
				returnGroup = 'I';
			}
			else if(time <= 64 && time >= 46){
				returnGroup = 'J';
			}
			else if(time <= 45 && time >= 27){
				returnGroup = 'K';
			}
			else{
				returnGroup = 'L';
			}	
		}
		return returnGroup;
	}
	

        /**
         * DISCLAIMER: This is a PROTOTYPE and must NOT be used to plan real dives.
         * diveCheck:Checks to see if the dive is possible or not based on the criteria
         * @param depth
         * @param unit
         * @param time
         * @param group
         * @param repetiveDive
         * @return 
         */
	public boolean diveCheck(int depth, int unit, int time, char group, boolean repetiveDive){
    //Units are in meters, convert the depth to feet
		if(unit == 1){
			depth = (int) (depth * 3.2);
		}
                
                //If the dive is repetive, then the group is from the residualNitrogen
		if(repetiveDive)time += residualNitrogenCalc(group, depth, unit);
	  
		//All of the comparisons will be done with the depth in feet.
		//If the depth is over 130 feet or the time is over 150 min, dive is no possible.
    if(depth > 130 || time > 150){
			return false;
		}
    //Else if the depth is below or equal to 40 and the time greater than 150,
    //dive is not possible
		else if(depth <= 40 && time > 150){
			return false;
		}
    //else if the depth if below or equal to 50 and the time is greater than 100,
    //dive is not possible
		else if(depth <= 50 && time > 100){
			return false;
		}
    //else if the depth is below or equal to 60 and the time is greater than 80,
    //dive is not possible
		else if(depth <= 60 && time > 80){
			return false;
		}
    //else if the depth is below or equal to 70 and the time is greater than 70,
    //dive is not possible
		else if(depth <= 70 && time > 70){
			return false;
		}
    //else if the depth is below or equal to 80 and the time is greater than 60,
    //dive is not possible
		else if(depth <= 80 && time > 60){
			return false;
		}
    //else if depth is below or equal to 90 and the time is greater than 50,
    //dive is not possible
		else if(depth <= 90 && time > 50){
			return false;
		}
    //else if the depth if below or equal to 100 and the time is greater than 40,
    //dive is not possible
		else if(depth <= 100 && time > 40){
			return false;
		}
    //else if the depth if below or equal to 110 and the time is greater than 30,
    //dive is not possible
		else if(depth <= 110 && time > 30){
			return false;
		}
    //else if the depth is below or equal to 120 and the time is greater than 30
    //dive is not possible
		else if(depth <= 120 && time > 30){
			return false;
		}
    //else if the dpeth is below or equal to 130 and the time is greater than 25
    //dive is not possible
		else if(depth <= 130 && time > 25){
			return false;
		}
    //else the dive is possible
		else{
			return true;
		}
	}
	
	/*DISCLAIMER: This is a PROTOTYPE and must NOT be used to plan real dives.
	 * 
	 * Checks if the dive requires decompression stops.
	 * 
	 * 
	 * @return the amount of time that is needed for a decompression stop at every 15 feet.
	 */
	public int diveDecompressionStopTime(int depth, int unit, int time, String group){
		int returnTime = 0;
		
		if(unit == 1){
			depth = (int) (depth * 3.2);
		}
		
		//Depth is done in feet
		if(depth <= 40 && (time > 130 && time <= 150)){
			returnTime = 5;
		}
		else if(depth <= 50 && (time > 80 && time <= 100)){
			returnTime = 5;
		}
		else if(depth <= 60 && (time > 55 && time <= 60)){
			returnTime = 5;
		}
		else if(depth <= 60 && (time > 60 && time <= 80)){
			returnTime = 7;
		}
		else if(depth <= 70 && (time > 45 && time <= 50)){
			returnTime = 5;
		}
		else if(depth <= 70 && (time > 50 && time <= 60)){
			returnTime = 8;
		}
		else if(depth <= 70 && (time > 60 && time <= 70)){
			returnTime = 14;
		}
		else if(depth <= 80 && (time > 35 && time <= 40)){
			returnTime = 5;
		}
		else if(depth <= 80 && (time > 40 && time <= 50)){
			returnTime = 10;
		}
		else if(depth <= 80 && (time > 50 && time <= 60)){
			returnTime = 17;
		}
		else if(depth <= 90 && (time > 25 && time <= 30)){
			returnTime = 5;
		}
		else if(depth <= 90 && (time > 30 && time <= 40)){
			returnTime = 7;
		}
		else if(depth <= 90 && (time > 40 && time <= 50)){
			returnTime = 18;
		}
		else if(depth <= 100 && (time > 22 && time <= 25)){
			returnTime = 5;
		}
		else if(depth <= 100 && (time > 25 && time <= 40)){
			returnTime = 15;
		}
		else if(depth <= 110 && (time > 15 && time <= 20)){
			returnTime = 5;
		}
		else if(depth <= 110 && (time > 20 && time <= 30)){
			returnTime = 7;
		}
		else if(depth <= 120 && (time > 12 && time <= 15)){
			returnTime = 5;
		}
		else if(depth <= 120 && (time > 15 && time <= 25)){
			returnTime = 6;
		}
		else if(depth <= 120 && (time > 25 && time <= 30)){
			returnTime = 14;
		}
		else if(depth <= 130 && (time > 8 && time <= 10)){
			returnTime = 5;
		}
		else if(depth <= 130 && (time > 10 && time <= 25)){
			returnTime = 10;
		}
		return returnTime;
	}
  
  /* DISCLAIMER: This is a PROTOTYPE and must NOT be used to plan real dives.
   * residualNitrogenCalc: takes in the group, depth, and unit
	 * and calculates the amount of residual nitrogen the user has
	 * based on those inputs
	 * 
	 */
	public int residualNitrogenCalc(char group, int depth, int unit){
		//convert from meters to feet. All calculations will be done in feet
		if(unit == 1){
			depth = (int) (depth * 3.2);
		}
		
		//Group A calculations
		if(group == 'A' && depth <= 40){
			return 7;
		}
		
		else if(group == 'A' && depth <= 50){
			return 6;
		}
		else if(group == 'A' && depth <= 60){
			return 5;
		}
		else if (group == 'A' && depth <= 70){
			return 4;
		}
		else if(group == 'A' && depth <= 80){
			return 4;
		}
		else if(group == 'A' && depth <= 90){
			return 3;
		}
		else if(group == 'A' && depth <= 100){
			return 3;
		}
		else if(group == 'A' && depth <= 110){
			return 3;
		}
		else if(group == 'A' && depth <= 120){
			return 3;
		}
		else if(group == 'A' && depth <= 130){
			return 3;
		}
		
		//group B calculations
		else if(group == 'B' && depth <= 40){
			return 17;
		}
		else if(group == 'B' && depth <= 50){
			return 13;
		}
		else if(group == 'B' && depth <= 60){
			return 11;
		}
		else if(group == 'B' && depth <= 70){
			return 9;
		}
		else if(group == 'B' && depth <= 80){
			return 8;
		}
		else if(group == 'B' && depth <= 90){
			return 7;
		}
		else if(group == 'B' && depth <= 100){
			return 7;
		}
		else if(group == 'B' && depth <= 110){
			return 6;
		}
		else if(group == 'B' && depth <= 120){
			return 6;
		}
		else if (group == 'B' && depth <= 130){
			return 6;
		}
		
		//Group C calculations
		else if(group == 'C' && depth <= 40){
			return 25;
		}
		else if(group == 'C' && depth <= 50){
			return 21;
		}
		else if(group == 'C' && depth <= 60){
			return 17;
		}
		else if(group == 'C' && depth <= 70){
			return 15;
		}
		else if(group == 'C' && depth <= 80){
			return 13;
		}
		else if(group == 'C' && depth <= 90){
			return 11;
		}
		else if(group == 'C' && depth <= 100){
			return 10;
		}
		else if(group == 'C' && depth <= 110){
			return 10;
		}
		else if(group == 'C' && depth <= 120){
			return 9;
		}
		else if (group == 'C' && depth <= 130){
			return 8;
		}
		
		//Group D calculations
		else if(group == 'D' && depth <= 40){
			return 37;
		}
		else if(group == 'D' && depth <= 50){
			return 29;
		}
		else if(group == 'D' && depth <= 60){
			return 24;
		}
		else if(group == 'D' && depth <= 70){
			return 20;
		}
		else if(group == 'D' && depth <= 80){
			return 18;
		}
		else if(group == 'D' && depth <= 90){
			return 16;
		}
		else if(group == 'D' && depth <= 100){
			return 14;
		}
		else if(group == 'D' && depth <= 110){
			return 13;
		}
		else if(group == 'D' && depth <= 120){
			return 12;
		}
		else if (group == 'D' && depth <= 130){
			return 11;
		}
		
		//Group E calculations
		else if(group == 'E' && depth <= 40){
			return 49;
		}
		else if(group == 'E' && depth <= 50){
			return 38;
		}
		else if(group == 'E' && depth <= 60){
			return 30;
		}
		else if(group == 'E' && depth <= 70){
			return 26;
		}
		else if(group == 'E' && depth <= 80){
			return 23;
		}
		else if(group == 'E' && depth <= 90){
			return 20;
		}
		else if(group == 'E' && depth <= 100){
			return 18;
		}
		else if(group == 'E' && depth <= 110){
			return 16;
		}
		else if(group == 'E' && depth <= 120){
			return 15;
		}
		else if (group == 'E' && depth <= 130){
			return 13;
		}
		
		//Group F calculations
		else if(group == 'F' && depth <= 40){
			return 61;
		}
		else if(group == 'F' && depth <= 50){
			return 47;
		}
		else if(group == 'F' && depth <= 60){
			return 36;
		}
		else if(group == 'F' && depth <= 70){
			return 31;
		}
		else if(group == 'F' && depth <= 80){
			return 28;
		}
		else if(group == 'F' && depth <= 90){
			return 24;
		}
		else if(group == 'F' && depth <= 100){
			return 22;
		}
		else if(group == 'F' && depth <= 110){
			return 20;
		}
		else if(group == 'F' && depth <= 120){
			return 18;
		}
		else if (group == 'F' && depth <= 130){
			return 16;
		}
		
		//Group G Calculations
		else if(group == 'G' && depth <= 40){
			return 73;
		}
		else if(group == 'G' && depth <= 50){
			return 56;
		}
		else if(group == 'G' && depth <= 60){
			return 44;
		}
		else if(group == 'G' && depth <= 70){
			return 37;
		}
		else if(group == 'G' && depth <= 80){
			return 32;
		}
		else if(group == 'G' && depth <= 90){
			return 29;
		}
		else if(group == 'G' && depth <= 100){
			return 26;
		}
		else if(group == 'G' && depth <= 110){
			return 24;
		}
		else if(group == 'G' && depth <= 120){
			return 21;
		}
		else if (group == 'G' && depth <= 130){
			return 19;
		}
		
		//Group H calculations
		else if(group == 'H' && depth <= 40){
			return 87;
		}
		else if(group == 'H' && depth <= 50){
			return 66;
		}
		else if(group == 'H' && depth <= 60){
			return 52;
		}
		else if(group == 'H' && depth <= 70){
			return 43;
		}
		else if(group == 'H' && depth <= 80){
			return 38;
		}
		else if(group == 'H' && depth <= 90){
			return 33;
		}
		else if(group == 'H' && depth <= 100){
			return 30;
		}
		else if(group == 'H' && depth <= 110){
			return 27;
		}
		else if(group == 'H' && depth <= 120){
			return 25;
		}
		else if (group == 'H' && depth <= 130){
			return 22;
		}
		//Group I calculations
		else if(group == 'I' && depth <= 40){
			return 101;
		}
		else if(group == 'I' && depth <= 50){
			return 76;
		}
		else if(group == 'I' && depth <= 60){
			return 61;
		}
		else if(group == 'I' && depth <= 70){
			return 50;
		}
		else if(group == 'I' && depth <= 80){
			return 43;
		}
		else if(group == 'I' && depth <= 90){
			return 38;
		}
		else if(group == 'I' && depth <= 100){
			return 34;
		}
		else if(group == 'I' && depth <= 110){
			return 31;
		}
		else if(group == 'I' && depth <= 120){
			return 28;
		}
		else if(group == 'I' && depth <= 130){
			return 25;
		}
		
		//Group J calculations
		else if(group == 'J' && depth <= 40){
			return 116;
		}
		else if(group == 'J' && depth <= 50){
			return 87;
		}
		else if(group == 'J' && depth <= 60){
			return 70;
		}
		else if(group == 'J' && depth <= 70){
			return 57;
		}
		else if(group == 'J' && depth <= 80){
			return 48;
		}
		else if(group == 'J' && depth <= 90){
			return 43;
		}
		else if(group == 'J' && depth <= 100){
			return 38;
		}
		
		//Group K Calculations
		else if(group == 'K' && depth <= 40){
			return 138;
		}
		else if(group == 'K' && depth <= 50){
			return 99;
		}
		else if(group == 'K' && depth <= 60){
			return 79;
		}
		else if(group == 'K' && depth <= 70){
			return 64;
		}
		else if(group == 'K' && depth <= 80){
			return 54;
		}
		else if(group == 'K' && depth <= 90){
			return 47;
		}
		
		//Group L calculations
		else if(group == 'L' && depth <= 40){
			return 161;
		}
		else if(group == 'L' && depth <= 50){
			return 111;
		}
		else if(group == 'L' && depth <= 60){
			return 88;
		}
		else if(group == 'L' && depth <= 70){
			return 72;
		}
		else if(group == 'L' && depth <= 80){
			return 61;
		}
		else if(group == 'L' && depth <= 90){
			return 53;
		}
		else if(group == 'B' && depth <= 100){
			return 7;
		}
		
		else{
			return 0;
		}
	}
   
}